<?php
$adm_menu = "1";

include("config.php");
if (!isset($_SESSION["auser"]) || $_SESSION["auser"] == "" || $_SESSION['agroup'] != "WEB_ADMIN") {
header('Location: index.php');
die();
}


$db_www = new DB($server_username,$server_pass,$server_db,$server,$driver);
$db_rdata = new DB($rdata_server_username,$rdata_server_pass,$rdata_server_db,$rdata_server,$rdata_driver);
if (!$db_rdata->isConnected()) {	
	die("Klientų aptarnavimo sistema laikinai neveikia(rdata).");
}	

include("header.php");
include("menu.php");




if (isset($_REQUEST["act"])){
 if ($_REQUEST["act"] == "del" && isset($_REQUEST["id"]) && (is_numeric($_REQUEST["id"]))){
		$sql ='select count(*) as cnt from ws_users where role_id='.$_REQUEST["id"];
		$ns = $db_rdata->returnInfo($sql);
		if ($ns["cnt"]==0){
			$roledel_query = str_replace("<id>", @iconv('UTF-8','windows-1257',addslashes_mssql($_REQUEST["id"])), $roledel_query);
			$db_rdata->execute($roledel_query);	
			$err = "";
		} else {
			$err = "Negalima trinti roles, kuriai yra priskirtu aparatu!";
		}
	}
}



?>




<?php

echo "<table class='innercont' cellspacing='0' cellpadding='0'><tr><td colspan='2'>&nbsp;</td></tr>";
echo "<tr><td class='leftcol' style='text-align:right;'>";


?>
<table cellspacing="0" cellpadding="5" class="params" style="">
<tr>
<td style="text-align:center;"><a id="newButton" href="role.php" class="card3">Nauja rolė</a></td>
</tr>
</table>
<br>




	
<?php

echo "</td>";
echo "<td class='rightcol'>";
?>
<?php
if (isset($err) && $err != ""){
	echo "<p style='background-color:transparent;color:red;font-weight:bold;font-size:10px;'>".$err."</p>";
}
?>
<script>
var id = null;

function modVouncher(iid){
    id = iid;
	window.location='role.php?uid='+iid;
}


function delVoucher(id){
	var answer = confirm("Ar ištrinti rolę?");
	if (answer){
		window.location='roles.php?act=del&id='+id ;
	}

}



</script>
<?php
	
	$ns = $db_rdata->returnList('select * from ws_roles_h');
	echo '<table class="innercont2" cellspacing="0" cellpadding="2" style="width:300px;"><tr><th>Rolės Id</th><th>Rolės pavadinimas</th><th></th>';
		

	echo '</tr>';
	$vsuma = 0;
	$vmok = 0;
	
	foreach ($ns as $kvitas) {
		$click = "onclick=\"modVouncher('".$kvitas["role_id"]."');\" class='click'";
		echo "<tr >";
		echo "<td $click >".$kvitas["role_id"]."</td>";
		echo "<td nowrap $click>".@iconv('windows-1257','UTF-8',$kvitas["role_pav"])."</td>";
		echo "<td class='click' onclick=\"delVoucher('".$kvitas["role_id"]."');return false;\"><img src='img/delete.jpg' width='11' alt='Trinti' title='Trinti'></td>";
		echo "</tr >";
	}

	
	echo "</table>";
	?>
	<br ><br >
<Button id='unblockButton' class='but bgwhite nopad' onclick="window.location='<?php echo "terminals.php"?>';return false;">Atgal</Button>
<?php	
	echo "</td></tr></table>";

include("footer.php");
?>